import { ComponentProps, VueComponent } from "vue3-oop"
import { FormItem, RadioGroup, Radio } from 'ant-design-vue';
import { WidgetNode } from '../../types'
import { RADIO } from "./attr-radio";

interface IProps {
  widgetNode: WidgetNode
}
export default class FvrRadio extends VueComponent<IProps> {
  static defaultProps: ComponentProps<IProps> = {
    widgetNode: {}
  }

  constructor(
  ) {
    super();
  }

  render() {
    const { widgetNode } = this.props;
    const { widgetItem } = widgetNode;
    const attr = widgetItem[widgetItem.type] as RADIO;

    const labelAlign = attr.formitem_labelAlign;
    const labelCol = { style: { width: `${attr.formitem_labelWidth}px` } }
    const isRequired = attr.layout_status==='4'

    return (
      <FormItem labelCol={labelCol} labelAlign={labelAlign} label={attr.field_label} required={isRequired}>
        <RadioGroup>
          {attr.options.map((option)=><Radio value={option.value}>{option.label}</Radio>)}
        </RadioGroup>
      </FormItem>
    )
  }
}